package com.tv.enoguia;

import java.util.ArrayList;
import java.util.HashMap;

import org.w3c.dom.Document;
import org.w3c.dom.Element;
import org.w3c.dom.NodeList;

import com.tv.enoguia.Utils.XMLParser;
import com.tv.enoguia.bean.Celler;
import com.tv.enoguia.database.MySQLiteHelper;


import android.app.TabActivity;
import android.content.Intent;
import android.os.AsyncTask;
import android.os.Bundle;
import android.util.Log;
import android.view.LayoutInflater;
import android.view.View;
import android.view.View.OnClickListener;
import android.widget.ImageView;
import android.widget.TabHost;
import android.widget.TabHost.TabSpec;

@SuppressWarnings("deprecation")
public class MainActivity extends TabActivity {

	static TabHost tabHost;
	String value;
	
	

	@Override
	protected void onCreate(Bundle savedInstanceState) {
		super.onCreate(savedInstanceState);
		setContentView(R.layout.activity_main_tab);
		
		
		value = getIntent().getStringExtra("value");
		
		tabHost = getTabHost();
		setTabs();
		tabHost.setCurrentTab(Integer.parseInt(value));
		
	}

	public void setTabs() {
		addTab("Home", R.drawable.tab_home_selector, HomeSreenActivity.class);
		addTab("List", R.drawable.tab_cellar_selector, ListCategoriesActivity.class);
		addTab("Location", R.drawable.tab_map_selector, LocationActivity.class);
		addTab("Favourite", R.drawable.tab_favor_selector, FavouriteActivity.class);
		
		/*TabHost tabHost = getTabHost();
		
		// Tab for Photos
	    TabSpec homespec = tabHost.newTabSpec("Home");
	    homespec.setIndicator("Home", getResources().getDrawable(R.drawable.tab_home));
	    Intent homeIntent = new Intent(this, HomeSreenActivity.class);
	    homespec.setContent(homeIntent);
	     
	    // Tab for Photos
	    TabSpec photospec = tabHost.newTabSpec("Photos");
	    photospec.setIndicator("Photos", getResources().getDrawable(R.drawable.tab_cellar_selector));
	    Intent photosIntent = new Intent(this, ListCategoriesActivity.class);
	    photospec.setContent(photosIntent);
	     
	    // Tab for Songs
	    TabSpec songspec = tabHost.newTabSpec("Songs");
	    // setting Title and Icon for the Tab
	    songspec.setIndicator("Songs", getResources().getDrawable(R.drawable.tab_map_selector));
	    Intent songsIntent = new Intent(this, LocationActivity.class);
	    songspec.setContent(songsIntent);
	     
	    // Tab for Videos
	    TabSpec videospec = tabHost.newTabSpec("Videos");
	    videospec.setIndicator("Videos", getResources().getDrawable(R.drawable.tab_favor_selector));
	    Intent videosIntent = new Intent(this, FavouriteActivity.class);
	    videospec.setContent(videosIntent);
	     
	    // Adding all TabSpec to TabHost
	    tabHost.addTab(homespec);
	    tabHost.addTab(photospec); // Adding photos tab
	    tabHost.addTab(songspec); // Adding songs tab
	    tabHost.addTab(videospec); // Adding videos tab 
*/	    
	    tabHost.getTabWidget().getChildAt(0).setOnClickListener(new OnClickListener() {
			
			@Override
			public void onClick(View v) {
				finish();
			}	
		});
		
	}

	private void addTab(String labelId, int drawableId, Class<?> c) {
		Intent intent = new Intent(this, c);
		TabHost.TabSpec spec = tabHost.newTabSpec("tab" + labelId);

		View tabIndicator = LayoutInflater.from(this).inflate(
				R.layout.tab_indicator, getTabWidget(), false);
		ImageView icon = (ImageView) tabIndicator.findViewById(R.id.icon);
		icon.setImageResource(drawableId);

		spec.setIndicator(tabIndicator);
		spec.setContent(intent);
		tabHost.addTab(spec);
	}
	
	public static int getCurrentTab(){
		return tabHost.getCurrentTab();
	}
	
	
}
